<template>
  <div>
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="顾客姓名" prop="customerName">
        <el-input
          v-model="queryParams.elderName"
          placeholder="请输入顾客姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="订单日期" prop="orderTime">
        <el-input
          v-model="queryParams.orderTime"
          placeholder="请输入订单日期"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="orderList" >
      <el-table-column label="订单号" align="center" prop="orderId" width="200px"/>
      <el-table-column label="顾客姓名" align="center" prop="elderName" width="100px" />
<!--      <el-table-column label="房间类型" align="center" prop="roomType" width="100px"/>-->
      <el-table-column label="服务" align="center" prop="nurseContent" width="300px" show-overflow-tooltip/>
      <el-table-column label="订单日期" align="center" prop="orderTime" width="200px"/>
      <el-table-column label="订单状态" align="center" prop="orderStatus" width="100px">
        <template v-slot="{ row }">
          <el-tag type="warning" v-show="row.orderStatus == 0 ">未支付</el-tag>
          <el-tag type="success" v-show="row.orderStatus == 1 ">已支付</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="备注" align="center" prop="notes" width="100px" show-overflow-tooltip/>
      <el-table-column label="订单金额" align="center" prop="totalAmount" width="100px">
        <template v-slot="{ row }">
          <el-tag type="success">{{ row.totalAmount }}</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
          >支付成功</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>


<script>
  import {getOrderList, updateOrder} from "@/api/business/order";
  export default {
    name: "payRecord",
    data() {
      return {
        // 遮罩层
        loading: true,
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          elderName: null,
          orderTime: null,
          orderStatus: null,
        },
        form: {
          customerName: null,
        },
        orderList:{},
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
      }
    },
    created() {
      this.getList();
    },
    methods: {
      getList(){
        this.loading = true;
        getOrderList(this.queryParams).then(response => {
          this.orderList = response.rows;
          this.total = response.total;
          this.loading = false;
        })
      },
      /** 搜索按钮操作 */
      handleQuery(){
        this.queryParams.pageNum = 1;
        this.getList();
      },
      handleUpdate(row){
        console.log(row);
        if(row.orderStatus == 0) {
          updateOrder(row).then(response => {
            this.$message.success("支付成功");
            this.getList();
          })
        }else {
          this.$message.error("订单已支付");
        }
      },
    }
  }
</script>

<style scoped>

</style>
